<extend name="public:base"/>

<block name="css">
    <link rel="stylesheet" href="__CSS__/member.css?v={:config('app_ver')}"/>
    <link rel="stylesheet" href="__CSS__/sign.css?v={:config('app_ver')}"/>
    <style>
        .inputWrapper.add_bankcard {
            padding-top: 10px;
        }

        .inputWrapper.add_bankcard td:last-child {
            padding: 0;
        }

        .inputWrapper.add_bankcard td:first-child {
            padding: 0 20px 0 0;
        }
    </style>
</block>

<block name="main">

    <div class="slide_main fr">
        <h1 class="frame_title mb10">收货地址</h1>
        <div class="frame_slide" id="rotate">

            <include file="safe:menu"/>

        </div>
        <div class="frame_slide_con bd">
            <div class="registerStep noPadding">


                <notempty name="list">

                    <div class="frame_slide_con">

                        <!-- 充值记录 -->
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tableBlue">
                            <tr class="first">
                                <th class="first">编号</th>
                                <th>真实姓名</th>
                                <th>账号类型</th>
                                <th>账号</th>
                            </tr>

                            <notempty name="list">
                                <volist name="list" id="v">
                                    <tr>
                                        <td class="first">{$i}</td>
                                        <td>{$v.full_name}</td>
                                        <td>{$v.bank_name}</td>
                                        <td>{$v.card_id}</td>
                                    </tr>
                                </volist>

                                <else/>

                                <td colspan="100" class="text-center"> 暂无内容</td>
                            </notempty>
                        </table>
                    </div>

                    <else/>

                    <!-- 修改密码 -->
                    <form action="{:url('user/safe/bank')}" method="post" id="addWithdrawInfo">
                        <input type="hidden" id="bank_name" name="bank_name"/>
                        <input type="hidden" id="bank_code" name="bank_code"/>

                        <div class="inputWrapper add_bankcard" style="width: 100%;">
                            <table width="100%">

                                <tr>
                                    <td class="a666" style="line-height: 44px;" valign="top" align="right">提现到账方式</td>
                                    <td>
                                        <div class="inputBox">

                                            <select name="type" id="way" class="input">
                                                <foreach name="way" item="v">
                                                    <option value="{$key}">{$v}</option>
                                                </foreach>
                                            </select>

                                            <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                                        </div>
                                    </td>
                                </tr>

                                <tr>
                                    <td class="a666" width="100px" style="line-height: 44px;" valign="top"
                                        align="right">真实姓名
                                    </td>
                                    <td>
                                        <div class="inputBox">
                                            <input type="text" name="full_name" maxlength="20" value="" class="input"
                                                   id="name" placeholder="真实全名" required/>
                                            <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                                        </div>
                                    </td>
                                </tr>

                                <tr>
                                    <td class="a666" style="line-height: 44px;" valign="top" align="right">账号</td>
                                    <td>
                                        <div class="inputBox">
                                            <input type="text" name="card_id" value="" maxlength="200" class="input"
                                                   id="card_id" placeholder="请输入账号" required/>
                                            <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                                        </div>
                                    </td>
                                </tr>

                                <tr style="display: none" id="bankListTr">
                                    <td class="a666" style="line-height: 44px;" valign="top" align="right">开户银行</td>
                                    <td>
                                        <div class="inputBox">
                                            <select id="selectBank" class="input">
                                                <foreach name="bank_list" item="v">
                                                    <option value="{$v['bank_code']}">{$v['bank_name']}</option>
                                                </foreach>
                                            </select>

                                            <div class="inputTip"><i class="iconFont">&#xe62a;</i><span></span></div>
                                        </div>
                                    </td>
                                </tr>


                                <tr>
                                    <td>&nbsp;</td>
                                    <td>
                                        <div class="submitLine">
                                            <p class="mb20 mt10">
                                                <input type="hidden" name="id" value="0">
                                                <input type="submit" value="确认添加" class="btn_b" id="inputSubmit"/>
                                            </p>
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>

                    </form>

                </notempty>


            </div>
        </div>
    </div>

</block>

<block name="js">

    <script type="text/javascript" src="__JS__/sign.js?v={:config('app_ver')}"></script>
    <script type="text/javascript">
        $(function () {

            /**
             * TODO：AJAX提交，disable按钮和增加样式
             */
            $(document).ajaxStart(function () {
                $('#inputSubmit').addClass("disabled").attr("disabled", true).val('正在提交');
            }).ajaxStop(function () {
                $('#inputSubmit').removeClass("disabled").attr("disabled", false).val('确认添加');
            });

            $("#selectBank").each(function () {
                var select = $(this).find("option:selected");
                $("#bank_code").val(select.val());
                $("#bank_name").val(select.html());
                $(this).change(function () {
                    var name = $(this).find("option:selected").html();
                    $("#bank_code").val($(this).val());
                    $("#bank_name").val(name);
                });
            });

            $('#way').change(function () {
                var select = $(this).find("option:selected");
                $("#bank_name").val(select.html());

                if (select.val() == 3) {
                    $('#bankListTr').show();
                } else {
                    $('#bankListTr').hide();
                }
            });

            /**
             * TODO:AJAX 提交表单
             */
            $("#addWithdrawInfo").submit(function () {

                var self = $(this);

                $.post(self.attr("action"), self.serialize(), success, "json");
                return false;

                function success(data) {
                    if (data.code === 1) {
                        layer.alert(data.msg, {icon: 1}, function (index) {
                            if (data.data || data.url) {
                                var refer = data.data || data.url;
                                layer.close(index);
                                window.location.href = refer;
                                setTimeout(function () {
                                    window.location.href = refer;
                                }, 2000);
                            } else {
                                window.location.reload();
                            }
                        });
                    } else {
                        if (data.msg !== '') {
                            layer.alert(data.msg, {icon: 2});
                        } else {
                            checkErrorType(data);
                        }
                    }
                }
            });
        });
    </script>

</block>

